package com.example.ass.controller;



import com.example.ass.pojo.Article;
import com.example.ass.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping
    public List<Article> getAllArticles() {
        return articleService.findAll();
    }

    @GetMapping("/{id}")
    public Article getArticleById(@PathVariable Integer id) {
        return articleService.findById(id);
    }

    @PostMapping("/{id}")
    public void createArticle(@RequestBody Article article) {
        articleService.insert(article);
    }

    @PutMapping("/{id}")
    public void updateArticle(@PathVariable Integer id, @RequestBody Article article) {
        article.setId(id);
        articleService.update(article);
    }

    @DeleteMapping("/{id}")
    public void deleteArticle(@PathVariable Integer id) {
        articleService.delete(id);
    }
}